package cn.bugstack.initializr.rigger.domain.service.module.impl;

import cn.bugstack.initializr.rigger.domain.model.ProjectInfo;
import cn.bugstack.initializr.rigger.domain.model.WebLogAspectAopConfigInfo;
import cn.bugstack.initializr.rigger.domain.service.module.BaseModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.File;

@Service
public class GenerationWebLogAspectAopConfigInfo extends BaseModule {

    private Logger logger = LoggerFactory.getLogger(GenerationWebLogAspectAopConfigInfo.class);

    public void doGeneration(ProjectInfo projectInfo,String projectsRoot, String lastPackageName,String webLogAspectAopConfigInfoClassName) throws Exception {

        WebLogAspectAopConfigInfo webLogAspectAopConfigInfo = new WebLogAspectAopConfigInfo(projectInfo.getGroupId() + "." + lastPackageName,
                projectInfo.getName().toString());

        String packagePath = webLogAspectAopConfigInfo.getPackageName().replace(".", "/") + "/config/";

        File file = new File(projectsRoot + projectInfo.getArtifactId() + "/src/main/java/" + packagePath,
                webLogAspectAopConfigInfoClassName + ".java");

        // 写入文件
        super.writeFile(file, "WebLogAspectAopConfig.ftl", webLogAspectAopConfigInfo);

        logger.info("创建AOP类 WebLogAspectAopConfig.java {}", file.getPath());
    }


}
